package com.ykt.common.utils;

import java.util.List;

/**
 * sql工具类
 *
 * @author long.hua
 * @version 1.0.0
 * @since 2016-05-24 23:55
 */
public class SqlUtil {


    public static <T> String placeholder(T[] list) {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < list.length; i++) {
            sb.append("?").append(", ");
        }

        StringUtil.trimRight(sb, ", ");

        return sb.toString();
    }

    public static <T> String placeholder(List<T> list) {
        return placeholder(list.toArray());
    }

    public static <T> String fillPlaceholder(List<T> list) {
        return fillPlaceholder(list.toArray());
    }

    public static <T> String fillPlaceholder(T[] list) {
        StringBuilder sb = new StringBuilder();

        for (T item : list) {
            if (item instanceof String || item instanceof Character) {
                sb.append("'").append(item).append("'").append(", ");
            } else {
                sb.append(item).append(", ");
            }
        }

        StringUtil.trimRight(sb, ", ");

        return sb.toString();
    }

    public static void main(String[] args) {
        fillPlaceholder(Colls.toArrayList(1,2));
    }
}
